import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_base/common/fun.dart';

/// Create： Zhang 3/19/21 9:33 AM
/// 描述：网络请求

///get请求
void get(
  String url, {
  Map<String, dynamic>? parameters,
  @required Callback<dynamic>? callBack,
}) async {
  var response = await Dio().get(url, queryParameters: parameters);

  ///------打印日志---------------
  print("http请求:"
      "\nurl:${response.realUri.toString()}"
      "\n请求头:${response.headers.toString()}");
  print("结果:${response.data.toString()}");

  ///------end---------------

  ///结果回调
  callBack!(response.data);
}

///post请求
void post(
  String url, {
  Map<String, dynamic>? parameters,
  @required Callback<dynamic>? callBack,
}) async {
  var response = await Dio().post(url, queryParameters: parameters);

  ///------打印日志---------------
  print("http请求:"
      "\nurl:${response.realUri.toString()}"
      "\n请求头:${response.headers.toString()}");
  print("结果:${response.data.toString()}");

  ///------end---------------

  ///结果回调
  callBack!(response.data);
}
